package io.renren.modules.business.controller;

import java.util.Arrays;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.renren.modules.business.entity.ECodeTableEntity;
import io.renren.modules.business.service.ECodeTableService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 码表
 *
 * @author ${author}
 * @email ${email}
 * @date 2022-02-23 10:25:51
 */
@RestController
@RequestMapping("business/ecodetable")
public class ECodeTableController {

    @Autowired
    private ECodeTableService eCodeTableService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = eCodeTableService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 码表查询
     * @param codeValue
     * @param codeNum
     * @return
     */
    @GetMapping("/query")
    public R queryCode(@RequestParam(value = "codeValue", required = false) String codeValue,
                       @RequestParam(value = "codeNum", required = false) Integer codeNum) {
        return R.ok().put("page", eCodeTableService.queryCode(codeValue, codeNum));
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		ECodeTableEntity eCodeTable = eCodeTableService.getById(id);

        return R.ok().put("eCodeTable", eCodeTable);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ECodeTableEntity eCodeTable){
		eCodeTableService.save(eCodeTable);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ECodeTableEntity eCodeTable){
		eCodeTableService.updateById(eCodeTable);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		eCodeTableService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
